﻿//-----------------------------------------------------------------------
// <copyright file="Item.cs" company="Forebrain Technology, LLC">
//
// Copyright (c) Forebrain Technology, LLC. All rights reserved.
// 
// This source code is released under the Microsoft Public License (Ms-PL).
//
// </copyright>
//-----------------------------------------------------------------------
namespace PivotCollectionTools.Xml
{
    using System;
    using System.Collections.ObjectModel;
    using System.Xml;
    using System.Xml.Serialization;

    /// <summary>
    /// An individual item in a collection.
    /// </summary>
    /// <remarks>
    /// This is where each individual item in the collection is defined, this node usually contains the 
    /// majority of the information in the file. Each item can have properties such as a double-click action 
    /// link, Href; a name, Name; a description, Description; an id, Id; an image asset, Img; or any number 
    /// of custom properties declared in the Facets section.
    /// </remarks>
    [Serializable()]
    [XmlType(Namespace = "http://schemas.microsoft.com/collection/metadata/2009")]
    public class Item : XmlNodeBase
    {
        /// <summary>
        /// Collection used to store the facet objects.
        /// </summary>
        private FacetCollection facets;

        /// <summary>
        /// Collection used to store tags for an item.
        /// </summary>
        private Collection<Tag> tags;

        /// <summary>
        /// Initializes a new instance of the <see cref="Item"/> class.
        /// </summary>
        public Item()
        {
            this.facets = new FacetCollection();
            this.tags = new Collection<Tag>();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Item"/> class.
        /// </summary>
        /// <param name="identifier">The identifier.</param>
        public Item(string identifier)
            : this()
        {
            this.Identifier = identifier;
        }

        /// <summary>
        /// Gets or sets the description.
        /// </summary>
        /// <value>The description of the item.</value>
        public string Description { get; set; }

        /// <summary>
        /// Gets the facets.
        /// </summary>
        /// <value>The facets of the item.</value>
        public FacetCollection Facets
        {
            get
            {
                return this.facets;
            }
        }

        /// <summary>
        /// Gets the tags.
        /// </summary>
        /// <value>The tags of the item.</value>
        public Collection<Tag> Tags 
        { 
            get
            {
                return this.tags;
            }
        }

        /// <summary>
        /// Gets or sets the identifier.
        /// </summary>
        /// <value>The identifier of the item.</value>
        [XmlAttribute(AttributeName = "Id")]
        public string Identifier { get; set; }

        /// <summary>
        /// Gets or sets the image.
        /// </summary>
        /// <value>The image of the item.</value>
        [XmlAttribute(DataType = "anyURI", AttributeName = "Img")]
        public string Image { get; set; }

        /// <summary>
        /// Gets or sets the href.
        /// </summary>
        /// <value>The href of the item.</value>
        [XmlAttribute(DataType = "anyURI")]
        public string Href { get; set; }

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>The name of the item.</value>
        [XmlAttribute()]
        public string Name { get; set; }

        public override string ToString()
        {
            return this.Name;
        }

    }
}
